import { defineStore } from 'pinia'
const userStore = defineStore('user', {
  state: () => {
    return {
      role: localStorage.getItem('role') || '',
      token: localStorage.getItem('token') || '',
      userInfo: localStorage.getItem('userInfo')
        ? JSON.parse(localStorage.getItem('userInfo'))
        : {}
    }
  },
  actions: {
    INIT_USER_INFO({ role, token, userInfo }) {
      this.role = role
      this.token = token
      this.userInfo = userInfo
    },
    USER_LOGOUT() {
      // 清除缓存
      localStorage.removeItem('role')
      localStorage.removeItem('token')
      localStorage.removeItem('userInfo')
    }
  }
})
export default userStore